package com.feng.dao.elective;

import com.feng.dao.BaseDao;
import org.junit.Test;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class ElectiveDaoImpl implements ElectiveDao{
    public int addElective(Connection conn, String username, String courseID) throws SQLException {

        Connection connection = conn;
        PreparedStatement preparedStatement = null;
        String sql = "INSERT INTO elective (username,courseID) VALUE (?,?)";
        int rows = 0;

            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, username);
            preparedStatement.setString(2, courseID);
            rows = preparedStatement.executeUpdate();
        BaseDao.CloseResources(null, preparedStatement, null);

        return rows;
    }


    @Test
    public void test() throws SQLException {
        System.out.println(addElective(BaseDao.getConnection(), "fdj", "8888"));
    }
}
